/**
 * @class   wosh::MessageFilter
 * @brief   The class extends wosh::Message providing comparison methods.
 *          
 *
 *
 ****************************************************************************
 * @version $Id: MessageFilter.h 2867 2010-08-07 20:44:51Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Core_MessageFilter_H__
 #define __WOSH_Core_MessageFilter_H__

 #include <woshDefs.h>
 #include <core/Message.h>
 #include <core/Object.h>

namespace wosh {

class Bundle;
class PropertiesProvider;
class InterfacesProvider;
class BusConnector;

class MessageFilter : public Message
 {
	WOSH_SERIALIZABLE(wosh::MessageFilter)


	public:
		enum HEADER_FILTER_RESULT {
			HEADER_CMP_UNKNOWN				= 0x00,
			HEADER_CMP_VALID				= 0x01,
			HEADER_CMP_ERR_SOURCE			= 0x02,
			HEADER_CMP_ERR_DESTINATION		= 0x04,
			HEADER_CMP_ERR_BUS_SOURCE		= 0x08,
			HEADER_CMP_ERR_BUS_CURRENT		= 0x10,
			HEADER_CMP_ERR_BUS_DESTINATION	= 0x20 ///< 32
		 };

		enum CONTENT_FILTER_RESULT {
			CONTENT_CMP_UNKNOWN				= 0x00,
			CONTENT_CMP_VALID				= 0x01,
			CONTENT_CMP_EQUAL				= 0x03, ///< = CONTENT_CMP_VALID too
			CONTENT_CMP_ERR_DIFFERENT		= 0x04,
			CONTENT_CMP_ERR_CLASS			= 0x0C  ///<8+4=12 = CONTENT_CMP_ERR_DIFFERENT too
		 };
		enum CONTENT_FILTER_OPTIONS {
			CONTENT_OPT_NONE				= 0x00,
			CONTENT_OPT_EMPTYPATTERN		= 0x01,
			CONTENT_OPT_STRICTCLASSCHECK	= 0x02,
			CONTENT_OPT_ALLOWSUBCONTAINER	= 0x04
		 };

	public:
		virtual int validateMessageHeader( const Message& message ) const;
		virtual int validateMessageContent( const Message& message, int* comparison_result = NULL, int options = 0 ) const;

		static const char* getMessageHeaderFilterResultAsString( HEADER_FILTER_RESULT value_enum );
		static std::string getMessageHeaderFilterResultsAsString( int value_mask );
		static const char* getMessageContentFilterResultAsString( CONTENT_FILTER_RESULT value_enum );
		static std::string getMessageContentFilterResultsAsString( int value_mask );

	public:
		static bool isMessageTarget( const Message& message, const Object* object );
		static bool isMessageTarget( const Message& message, const URI& itemURI, const PropertiesProvider* properties = NULL, const InterfacesProvider* interfaces = NULL );
		static bool isMessageTarget( const Message& message, const Bundle* bundle );

	public:
		static short filterReplica( const Message& message, const BusConnector* mainBus );

	public:
		static bool validateExpression( const UriExpression& expression, const PropertiesProvider* properties, const InterfacesProvider* interfaces, const SecurityToken* security );


	public:
		MessageFilter() : Message() { }
		virtual ~MessageFilter() { }


}; // class def

}; // namespace wosh

#endif //__WOSH_Core_MessageFilter_H__
